//
//  MyCustomNavigationBar1.m
//  Fitness War
//
//  Created by zhu on 12-3-17.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "MyCustomNavigationBar1.h"


@implementation MyCustomNavigationBar1
@synthesize goldNumLabel,rankNumLabel,experienceNumLabel;
@synthesize rightBution;
@synthesize goldNumImg;

-(void) dealloc
{
    [goldNumLabel release];
    [rankNumLabel release];
    [experienceNumLabel release];
    [rightBution release];
    [goldNumImg release];
    
    [super dealloc];
    
}

-(id)init
{
    [super init];
    if (self) 
    {
        self.frame = CGRectMake(0, 0, 320, 32);
        //背景图片
        UIImageView *backgroundImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 34)];
        backgroundImg.image = [[UIImage imageNamed:@"nav_bar.png"]autorelease];
        [self addSubview:backgroundImg];
        
        //金钱
        UIImageView * goldImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 6, 16, 17)];
        goldImg.image = [[UIImage imageNamed:@"gold.png"]autorelease];
        [backgroundImg addSubview:goldImg];
        
        //金钱数字
       goldNumImg = [[UIImageView alloc] initWithFrame:CGRectMake(30, 8, 20, 15)];
        goldNumImg.image = [[UIImage imageNamed:@"nav_Gold1.png"]
                            autorelease];
        [backgroundImg addSubview:goldNumImg];
        
        //等级图
        UIImageView *rankImg = [[UIImageView alloc] initWithFrame:CGRectMake(126, 9.5, 30, 11)];
        rankImg.image = [[UIImage imageNamed:@"nav_Level.png"]autorelease];
        [backgroundImg addSubview:rankImg];
        
        //等级标签
        UILabel *rankLabel = [[UILabel alloc] initWithFrame:CGRectMake(98, 10, 28, 10)];
        rankLabel.text = @"等级";
        rankLabel.textColor =[UIColor orangeColor];
        rankLabel.font = [[UIFont systemFontOfSize:11]autorelease];
        rankLabel.backgroundColor = [UIColor clearColor];
        [backgroundImg addSubview:rankLabel];
        
        //经验标签
        UILabel *experienceLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 10, 28, 10)];
        experienceLabel.text = @"经验:";
        experienceLabel.textColor =[UIColor orangeColor];
        experienceLabel.font = [[UIFont systemFontOfSize:11]autorelease];
        experienceLabel.backgroundColor = [UIColor clearColor];
        [backgroundImg addSubview:experienceLabel];
        
        
        //金钱数字标签
        goldNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(37, 10, 7, 9)];
        goldNumLabel.text = @"0";
        goldNumLabel.textColor =[UIColor whiteColor];
        goldNumLabel.font = [[UIFont systemFontOfSize:12]autorelease];
        goldNumLabel.backgroundColor = [UIColor clearColor];
        [backgroundImg addSubview:goldNumLabel];
        
        //等级数字标签
       rankNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(135, 11, 17, 9)];
        rankNumLabel.text = @"1";
        rankNumLabel.textColor =[UIColor whiteColor];
        rankNumLabel.font = [[UIFont systemFontOfSize:11]autorelease];
        rankNumLabel.backgroundColor = [UIColor clearColor];
        [backgroundImg addSubview:rankNumLabel];
    
        
        //经验数字标签
        experienceNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(205, 10, 60, 9)];
        experienceNumLabel.text = @"0/279";
        experienceNumLabel.textColor =[UIColor orangeColor];
        experienceNumLabel.font = [[UIFont systemFontOfSize:12]autorelease];
        experienceNumLabel.backgroundColor = [UIColor clearColor];
        [backgroundImg addSubview:experienceNumLabel];
        
        //按钮
        rightBution = [[UIButton alloc] init];
        rightBution = [ UIButton buttonWithType:UIButtonTypeRoundedRect];
        [rightBution setFrame:CGRectMake(265, 2, 48, 23)];
        rightBution.font = [[UIFont systemFontOfSize:13]autorelease];
        [rightBution setTitle:@"返回" forState:UIControlStateNormal];
        [rightBution setBackgroundImage:[[UIImage imageNamed:@"nav_button.png"] autorelease] forState:UIControlStateNormal];
        [self addSubview:rightBution];
    
        [backgroundImg release];
        [goldImg release];
    }
    return self;
}

//设置金钱随金钱数增加 最大6位数
- (void)setMoneyNum:(int) _value
{
    
    
    NSString *tempStr = [NSString stringWithFormat:@"%d",_value];
    if(_value < 10)
    {
       goldNumLabel.text = tempStr;
    }
    else if(_value <100)
    {
        
        goldNumImg.frame = CGRectMake(30, 8, 33, 15);
        goldNumImg.image = [[UIImage imageNamed:@"nav_Gold2.png"]
                            autorelease];
        goldNumLabel.frame = CGRectMake(37, 10, 17, 9);
        goldNumLabel.text = tempStr;        
    }
    else if(_value <1000)
    {
        
        goldNumImg.frame = CGRectMake(30, 8, 38, 15);
        goldNumImg.image = [[UIImage imageNamed:@"nav_Gold3.png"]
                            autorelease];
        goldNumLabel.frame = CGRectMake(40, 10, 21, 9);
        goldNumLabel.text = tempStr;        
    }
    else if(_value <10000)
    {
        
        goldNumImg.frame = CGRectMake(30, 8, 43, 15);
        goldNumImg.image = [[UIImage imageNamed:@"nav_Gold4.png"]
                            autorelease];
        goldNumLabel.frame = CGRectMake(38.5, 10, 27, 9);
        goldNumLabel.text = tempStr;        
    }
    else if(_value <100000)
    {
        
        goldNumImg.frame = CGRectMake(30, 8,49, 15);
        goldNumImg.image = [[UIImage imageNamed:@"nav_Gold5.png"]
                            autorelease];
        goldNumLabel.frame = CGRectMake(38, 10, 35, 9);
        goldNumLabel.text = tempStr;        
    }
    else if(_value <1000000)
    {
        
        goldNumImg.frame = CGRectMake(30, 8,54, 15);
        goldNumImg.image = [[UIImage imageNamed:@"nav_Gold6.png"]
                            autorelease];
        goldNumLabel.frame = CGRectMake(37, 10, 42, 9);
        goldNumLabel.text = tempStr;        
    }


    [tempStr release];
}

//设置经验值
- (void)setExperienceValue:(NSString *)_value
{
    experienceNumLabel.text = _value;
}

//设置等级值
- (void)setRankValue:(int) _value
{
    NSString *tempStr = [NSString stringWithFormat:@"%d",_value];
    rankNumLabel.text = tempStr;
    [tempStr release];

}


@end
